﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;

namespace VMExplorer.Controls
{
  class RadioButton : System.Windows.Forms.RadioButton
  {
    Color _borderActive = Color.DodgerBlue;
    Color _borderInactive = SystemColors.Control;
    Color _bgMouseDown = SystemColors.Highlight;
    Color _bgMouseOver = Color.SkyBlue;

    public Color BorderActiveColor { get { return _borderActive; } set { _borderActive = value; } }
    public Color BorderInactiveColor { get { return _borderInactive; } set { _borderInactive = value; } }
    public Color BackgroundMouseDownColor { get { return _bgMouseDown; } set { _bgMouseDown = value; } }
    public Color BackgroundMouseOverColor { get { return _bgMouseOver; } set { _bgMouseOver = value; } }

    public RadioButton()
    {
      Appearance = System.Windows.Forms.Appearance.Button;
      FlatStyle = System.Windows.Forms.FlatStyle.Flat;
      FlatAppearance.BorderColor = _borderInactive;
      FlatAppearance.CheckedBackColor = System.Drawing.SystemColors.Control;
      FlatAppearance.MouseDownBackColor = _bgMouseDown;
      FlatAppearance.MouseOverBackColor = _bgMouseOver;
      UseVisualStyleBackColor = false;

      Size = new System.Drawing.Size(23, 23);

      MouseLeave += new System.EventHandler(OnMouseLeave);
      MouseEnter += new System.EventHandler(OnMouseEnter);
      CheckedChanged +=new EventHandler(OnCheckedChanged);
    }

    private void OnMouseEnter(object sender, EventArgs e)
    {
      FlatAppearance.BorderColor = _borderActive;
    }

    private void OnMouseLeave(object sender, EventArgs e)
    {
      if (!Checked) FlatAppearance.BorderColor = _borderInactive;
    }

    private void OnCheckedChanged(object sender, EventArgs e)
    {
      if (!Checked) FlatAppearance.BorderColor = _borderInactive;
      else FlatAppearance.BorderColor = _borderActive;
    }
  }
}
